
using System.Collections.Generic;
using System.Text;
using OpenServers.Net.Common.Utils;

namespace OpenServers.Net.HttpServer.Request {
    /// <summary>
    /// Storage for HTTP request information such as verb, url, headers, etc.
    /// </summary>
    public class HttpRequest {
        private readonly string _verb;
        private readonly Url _url;
        private readonly double _httpVersion;
        private readonly IDictionary<string, string> _header = new Dictionary<string, string>();

        /// <summary>
        /// construct.
        /// </summary>
        public HttpRequest(string verb, Url url, double httpVersion) {
            _verb = verb;
            _url = url;
            _httpVersion = httpVersion;
        }

        /// <summary>
        /// The verb used in the request. (get, post, etc.)
        /// </summary>
        public string Verb {
            get { return _verb; }
        }

        /// <summary>
        /// The url requested.
        /// </summary>
        public Url Url {
            get { return _url; }
        }

        /// <summary>
        /// The http request version.
        /// </summary>
        public double HttpVersion {
            get { return _httpVersion; }
        }

        /// <summary>
        /// The dictionary of header names/values.
        /// </summary>
        public IDictionary<string, string> Headers {
            get { return _header; }
        }

        ///<summary>
        ///Returns a <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
        ///</summary>
        ///
        ///<returns>
        ///A <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
        ///</returns>
        ///<filterpriority>2</filterpriority>
        public override string ToString() {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(string.Format("Verb: [{0}]", Verb));
            sb.AppendLine(string.Format("Url: [{0}]", Url));
            sb.AppendLine(string.Format("HttpVersion: [{0}]", HttpVersion));
            foreach (KeyValuePair<string, string> keyValuePair in _header) {
                sb.AppendLine(string.Format("Header [{0}]: [{1}]", keyValuePair.Key, keyValuePair.Value));
            }
            return sb.ToString();
        }
    }
}
